package com.review.study;

public class StringOperation {
    public static void main(String[] args) {
        char[] c = new char[30];
        String s = "12891$111213\\\n14";
        //将String中的一部分转化为字符数组；
        s.getChars(5, 12, c, 0);//从字符串中复制一段放置到数组中·；
        s.toCharArray();//将字符串转化为数组
        //替换
        String w1 = s.replace("\n", "w");
        //连接字符串；
        String s3 = "abc";
        String s2 = "def";
        String s4 = s3 + s2;
        //得到字符串“12”的下标
        int cc = s3.indexOf("ab");
        //判断是否存在某个字符串；
        System.out.println(s3.contains("bc"));
        System.out.println("下标为" + cc);
        String s5 = s3.concat(s2);
        String ww = s.replace("$", "ss");
        System.out.println("w1 " + w1);
        System.out.println("ww " + ww);
        String w2 = s.replaceAll(" \\n", "w");
        String ww2 = s.replaceAll("\\$", "w");
        System.out.println("w2 " + w2);
        System.out.println("ww2 " + ww2);
        //分割
        String w3[] = s.split("\\n");
        int a = 0;
        for (int i = 0; i < w3.length; i++) {
            a++;
            System.out.println(w3[i]);

        }
        System.out.println("共有几个数组" + a);
        //切割
        String bb = s.substring(3);
        //取子集时下标为endindex的字符不会被取到；
        String bb1 = s.substring(0, 5);
        System.out.println("bbbbbb1" + bb1);
        System.out.println("子集" + bb);
        String tt = " 123  er45  55   ";
        //tt.trim()去除字符串前后空格.采用替换的方式去掉中间空格.tt.replaceAll(" ","");
        System.out.println(tt.length());
        String tt1 = tt.trim();
        System.out.println(tt1);
        System.out.println(tt.trim().length());
        System.out.println(tt.replaceAll(" ", ""));
    }


}
